package com.cxyxj.propertysource;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@SpringBootApplication(scanBasePackages = "com.cxyxj.propertysource")
/**
 * Spring 环境需要显示指向 application.properties、application.yml
 */
//@ComponentScan(basePackages =  "com.cxyxj.propertysource")
//@PropertySource( value = {"juejin.yml","application.properties"},factory = YmlPropertyResourceFactory.class)
@PropertySource( value = {"juejin.yml"},factory = YmlPropertyResourceFactory.class)
public class AppMain {

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(AppMain.class);
       // AnnotationConfigApplicationContext application = new AnnotationConfigApplicationContext(AppMain.class);
        //获得容器的 Environment
        Environment env = application.getEnvironment();
        //根据key获取
        String blog = env.getProperty("blog.name");
        String juejin = env.getProperty("juejin.home");
        System.out.println(blog);
        System.out.println(juejin);
    }
}
